<template>
    <div class="ContractInfo" style="width: 100%;">
        <rui-form :form-options="formOptions" :label-width="120" :read-only="true" ref="formData">
            <template slot="affiliatedTypeTemp" slot-scope="{ key,data }">
                <span v-if="data[key] === 'NO'">无</span>
                <a v-else @click="openAffiliatedModal">{{ showAffiliatedInfo(data[key]) }}</a>
            </template>
            <template slot="specialProvisions" slot-scope="{ key,data }">
                <a  @click="openSpecialProvisions">{{specialProvisions(data[key]) }}</a>
            </template>
            <template slot-scope="{ key,data }" slot="channelName">
                <a @click="openModal">{{ data[key] }}</a>
            </template>
        </rui-form>
        <Modal title="业务合作伙伴详情" v-model="isModalOpen" :mask-closable="false" :width="950" :styles="{top: '30px'}">
            <BusinessPartnerDetial :contractNo="contractNo" :formData="formData" :dataDict="dataDict"/>
            <div slot="footer"></div>
        </Modal>
    </div>
</template>

<script>
import BusinessPartnerDetial from "./BusinessPartnerDetial";
import {channelInfo} from "_p/basic/api/contract/contract-detail-inquiry";
export default {
    components: {BusinessPartnerDetial},
    props: {
        dataDict: {
            type: Object,
            required: true
        },
        contractNo: {
            type: String,
            required: true
        }
    },
    data() {
        return {
            isModalOpen: false,
            formData: {
                channelAddress: []
            },
            defines: [],
            formOptions: [
                {
                    isGroup: false,
                    grids: [
                        {
                            defineId: "defineData",
                            span: 8,
                            fields: ["contractNo", "closeDate"]
                        },
                        {
                            defineId: "defineData",
                            span: 8,
                            fields: ["applyNo", "startDate"]
                        },
                        {
                            defineId: "defineData",
                            span: 8,
                            fields: ["contractStatus", "endDate"]
                        }
                    ]
                },
                {
                    isGroup: false,
                    grids: [
                        {
                            defineId: "defineData",
                            span: 8,
                            fields: [
                                "channelBelong",
                                "affiliatedType",
                                "fiveCategory"
                            ],
                            slots: [{key: 'affiliatedType', slotName: 'affiliatedTypeTemp'}]
                        },
                        {
                            defineId: "defineData",
                            span: 8,
                            fields: ["businessType", "specialProvisions","custName2"]
                        },
                        {
                            defineId: "defineData",
                            span: 8,
                            fields: ["gracePeriodDays", "currentAbsoluteOverdue","channelName"],
                            slots: [{key: 'channelName', slotName: 'channelName'}]
                        },
                    ]
                }
            ]
        };
    },

    mounted() {
    },
    methods: {
        openAffiliatedModal(){
            this.$emit('anchorInfoModalOpen')
        },
        showAffiliatedInfo(key) {
            // COMPANY_AFFILIATED   公司挂靠
            // PERSONAL_AFFILIATED 个人挂靠
            // NETWORK_CAR_AFFILIATED 网约车挂靠
            let str = '';

            switch (key) {
                case "COMPANY_AFFILIATED":
                    str = "第三方公司挂靠";
                    // this.formOptions = companyOptions;
                    break;
                case "PERSONAL_AFFILIATED":
                    str = "个体工商挂靠";
                    // this.formOptions = personalOptions;
                    break;
                case "NETWORK_CAR_AFFILIATED":
                    str = "网约车挂靠";
                    // this.formOptions = newworkOptions;
                    break;
            }
            return str;
        },
        getDetial() {
            channelInfo(this.contractNo).then(res => {
                console.log(res, "===");
                if (res.code === "0000") {
                    this.formData = res.data;
                    this.formData.channelAddress = [res.data.channelAdminProvince, res.data.channelAdminCity]
                }
            });
        },
        openModal() {
            this.isModalOpen = true;
            this.getDetial(this.contractNo);
        },
        updateData(data) {
            console.log('================================',data);
            if (!data) return;

            this.$refs.formData.updateFormData(data);
            if (data.specialProvisions === undefined) {
                this.$refs.formData.setFiledValue('specialProvisions', '0')
            }

            if (data.specialProvisionDate !== null) {
                this.$refs.formData.setFiledValue('specialProvisionDate', '0000-00-00')
            }
            if (data.endDate === undefined) {
                this.$refs.formData.setFiledValue('endDate', '0000-00-00')
            }
            // if (data.endDate === "9999-12-31") {
            //     this.$refs.formData.setFiledValue('endDate', '长期')
            // }
            if (data.closeDate === undefined) {
                this.$refs.formData.setFiledValue('closeDate', '0000-00-00')
            }
            console.log(data)
        }
    }
};
</script>

<style>
</style>
